<?php
/*
 * @Author: your name
 * @Date: 2021-12-13 13:32:45
 * @LastEditTime: 2021-12-13 13:59:15
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Http\Controllers\find_shop\Area.php
 */

namespace App\Http\Controllers\find_shop;

use Illuminate\Support\Facades\Request;
// use  App\Http\Controllers\redis\RedisController as Redis;
use  App\Models\admin_model\Area as AreaDb;

class Area extends BaseController
{
    public function areaList()
    {
        $areaListSelList =   AreaDb::areaListSelList('`id`,`id` as `value`,`name` as `text`,`pid`');
        $list = [];
        $keyArray = [];
        for($i=0;$i<count( $areaListSelList );$i++){
             if($areaListSelList[$i]['pid'] == 0){
                 $list[] = $areaListSelList[$i];
             }else{
                 if(!isset($keyArray[$areaListSelList[$i]['pid']])){
                     $keyArray[$areaListSelList[$i]['pid']] = [];
                 }
                 $keyArray[$areaListSelList[$i]['pid']][] = $areaListSelList[$i];
             }
        }
        for($i=0;$i<count( $list );$i++){
            if(isset($keyArray[ $list[$i]['id'] ] )){
              $list[$i]['child'] = $keyArray[ $list[$i]['id'] ];
            }  
        }
       return $this->create(200,'查询成功',$list);
    }
}
